<?php

defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'getorder';
if($_RQ['op']=='getorder'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if(isset($_RQ['status']) && $_RQ['status']!=100){
		$params['status']=intval($_RQ['status']);
		if($params['status']==5){
			$params['status']=array(5,6);
		}
		if($params['status']==2){
			$params['status']=array(2,3);
		}
		$return['params']['status']=intval($_RQ['status']);
	}else{
		$return['params']['status']=100;
	}
	//我的团
	//先查询我的订单
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_newpingfee_team_log',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			if($item['team_id']){
				$team=pdo_get('jy_newpingfee_team',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['team_id']));
				$item['team']=$team;
			}
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$team['goodsid']));
			$item['goodsid']=$team['goodsid'];
			$item['teamnum']=$this->model('team')->getteamnum($team);
			if(!$item['goods']['id']){
				unset($list[$k]);
			}
			$item['order']=pdo_get('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['orderid']),array('price'));
		}
	}
	$return['list']=$list;
	$return['address_list'] = pdo_getall('core_address',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if($return['address_list']){
		foreach($return['address_list'] as &$add){
			$add['pcd']=json_decode($add['pcd'],true);
		}
	}
	exi($return);
}
if($_RQ['op']=='getlist'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$params['status']=intval($_RQ['status']);
	$return['params']['status']=intval($_RQ['status']);
	//我的团
	//先查询我的订单
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$teams=pdo_getslice('jy_newpingfee_team',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($teams){
		foreach($teams as $k=>&$item){
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
			if(!$item['goods']['id']){
				unset($teams[$k]);
			}
			$item['teamnum']=$this->model('team')->getteamnum($team);
			$item['pai_fee']=$this->setting['pai_fee']*$item['goods']['price']/100;
			$item['order']=pdo_get('jy_newpingfee_team_log',array('uniacid'=>$_SESSION['uniacid'],'team_id'=>$item['id'],'mid'=>$item['mid']));
		}
	}
	$return['list']=$teams;
	exi($return);
}
if($_RQ['op']=='set_address'){
	$post=get_postdata();
	$id = intval($post['id']);
	$addressid = intval($post['addressid']);
	if(!$addressid){
		exi('请选择地址！','error');
	}
	$address=pdo_get('core_address',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'id'=>$addressid));
	pdo_update('jy_newpingfee_team_log',array('address'=>ijson_encode($address),'addressid'=>$addressid),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	exi('补填地址成功！');
}
if($_RQ['op']=='pay'){
	$id = intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}
	$pay_id=pdo_getcolumn('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'pay_id');
	exi($pay_id);
}
